var leftRightDifference = function(nums) {
    if(!(nums.length))return [0]
    let leftSum = new Array(nums.length).fill(0)
    let rightSum = new Array(nums.length).fill(0)
    let leftItem = 0
    let rightItem = 0

    for(let i=0;i<nums.length;i++){
        if(!(nums[i-1])){
            leftSum[i] = 0
        }else{
            leftItem = leftItem +nums[i-1]
            leftSum[i] = leftItem
        }

        if(!(nums[nums.length-i])){
            rightSum[nums.length-i-1] = 0
        }else{
            rightItem = rightItem + nums[nums.length-i]
            rightSum[nums.length-i-1] = rightItem
           
            
        }
    }
      return goodArr(leftSum,rightSum)
};

function goodArr(arr1,arr2){   
    let arr3 = new Array(arr1.length)
    for(let i=0;i<arr1.length;i++){
        if((arr1[i]-arr2[i])>0){
            arr3[i] = arr1[i] - arr2[i]
        }else{
            arr3[i] = arr2[i] - arr1[i]
        }
    }
    return arr3 
}
